local penglaiyuzhi_skill = fk.CreateSkill {
  name = "#penglaiyuzhi_skill",
  attached_equip = "penglaiyuzhi",

}



penglaiyuzhi_skill:addEffect(fk.PreCardEffect, {
  priority = 0.01,
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(penglaiyuzhi_skill.name) and data.card.trueName == "slash"
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = data.to
    local cancel = false
    local players = table.filter(room.alive_players, function(p)
      return not table.contains(data.use.disresponsiveList or Util.DummyTable, p) and not
          table.contains(data.use.unoffsetableList or Util.DummyTable, p)
    end)
    local useEvent = room.logic:getCurrentEvent():findParent(GameEvent.UseCard)
    if data.disresponsive or data.unoffsetable then
      table.removeOne(players, to)
    end
    local hasNullification = function(p)
      local temp = Fk.currentResponsePattern
      Fk.currentResponsePattern = "nullification"
      local check = function()
        local cardCloned = Fk:cloneCard("nullification")
        if p:prohibitUse(cardCloned) then return false end
        local cards = p:getHandlyIds()
        if table.find(cards, function(cid) return Fk:getCardById(cid).trueName == "nullification" end) then return true end
        Self = p -- for enabledAtResponse
        for _, s in ipairs(table.connect(p.player_skills, p._fake_skills)) do
          if s.pattern and Exppattern:Parse("nullification"):matchExp(s.pattern) and
              not (s.enabledAtResponse and not s:enabledAtResponse(p)) then
            return true
          end
        end
      end
      local yes = check()
      Fk.currentResponsePattern = temp
      return yes
    end
    players = table.filter(players, function(p)
      return hasNullification(p)
    end)
    if #players > 0 then
      local extra_data = Util.DummyTable
      if useEvent then
        extra_data = { useEventId = useEvent.id, effectTo = data.to.id }
      end
      local prompt = "#penglaiyuzhi-ask:" .. data.to.id
      local use = room:askForNullification(players, "nullification", "nullification", prompt, true, extra_data)
      if use then
        use.toCard = data.card
        use.responseToEvent = data
        room:useCard(use)
      end
      if data.isCancellOut then
        cancel = true
      end
    end
    if cancel then
      if room.logic:trigger(fk.CardEffectCancelledOut, target, data) then
        data.isCancellOut = false
        cancel = false
      end
    end
    if cancel then
      data.nullified=true
    else
      data.unoffsetable = true
    end
  end
})

return penglaiyuzhi_skill
